﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TcCommands.TcReloadResource.CCoTcReloadResourceCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using EngineeringInternalExtension.Utilities;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.TcCommands.TcReloadResource;

public class CCoTcReloadResourceCmd : TxButtonCommand
{
  protected CCoTcReloadResourceCmdEnabler m_cmdEnabler;

  public CCoTcReloadResourceCmd() => this.m_cmdEnabler = new CCoTcReloadResourceCmdEnabler();

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_cmdEnabler;

  public virtual string Name => TcReloadResourceStringTable.RELOAD_RESOURCE_CMD_NAME;

  public virtual string Category => TcReloadResourceStringTable.RELOAD_RESOURCE_CMD_CATEGORY;

  public virtual string Tooltip => TcReloadResourceStringTable.RELOAD_RESOURCE_CMD_TOOLTIP;

  public virtual string Description => TcReloadResourceStringTable.RELOAD_RESOURCE_CMD_DESCRIPTION;

  public virtual string LargeBitmap => "TcCommands.TcReloadResource.Images.ReloadResource_32.png";

  public virtual string Bitmap => "TcCommands.TcReloadResource.Images.ReloadResource_16.bmp";

  public virtual string MediumBitmap => "TcCommands.TcReloadResource.Images.ReloadResource_24.png";

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("ReloadResource");

  public virtual void Execute(object cmdParams)
  {
    if (!this.ConfirmExecution() || !TcCommandsUtility.PromptSaveStudyAndProceed(TcReloadResourceStringTable.RELOAD_RESOURCE_SAVE_TEXT, base.Name))
      return;
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    TxErrorStack.Clear();
    try
    {
      TxObjectList allItems = TxApplication.ActiveSelection.GetAllItems();
      List<TxProcessModelId> txProcessModelIdList = new List<TxProcessModelId>();
      foreach (ITxObject itxObject in (Collection<ITxObject>) allItems)
      {
        if (itxObject is ITxComponent itxComponent)
        {
          TxProcessModelId prototypeProcessModelId = TxEngineeringDataInternal.GetComponentPrototypeProcessModelId(itxComponent);
          if (TxProcessModelId.op_Inequality((TxProcessModelId) null, prototypeProcessModelId) && !txProcessModelIdList.Contains(prototypeProcessModelId))
            txProcessModelIdList.Add(prototypeProcessModelId);
        }
      }
      TxTcUtilities.ReloadResourcePrototypes(txProcessModelIdList);
      TxTcUtilities.ReloadTechnologies(false);
    }
    catch (TxException ex)
    {
      int num = (int) TxMessageBox.Show(TcReloadResourceStringTable.RELOAD_RESOURCE_FAILURE, TcReloadResourceStringTable.RELOAD_RESOURCE_CMD_NAME, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
    finally
    {
      Cursor.Current = current;
      TxErrorStackDlg.DisplayErrors();
    }
  }

  private bool ConfirmExecution()
  {
    return TxDoNotShowAgainMessageBox.Show(TcReloadResourceStringTable.RELOAD_RESOURCE_CONFIRM_EXECUTION, TcReloadResourceStringTable.RELOAD_RESOURCE_CMD_NAME, "TcReloadResourceCmd_ConfirmExecution", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, DialogResult.Yes) == DialogResult.Yes;
  }
}
